/**
 * 学习目标：使用ref-获取DOM节点
 */
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
  // 1. 创建ref对象
  iptRef = React.createRef();

  render() {
    return (
      <div>
        {/* // 2. 绑定ref到DOM或组件身上 */}
        <input type="text" ref={this.iptRef} />
        <button onClick={this.handleClick}>点我获取DOMipt</button>
      </div>
    );
  }

  handleClick = () => {
    // 3. 使用ref.current获取DOM
    console.log(' this.iptRef  ----->  ', this.iptRef);
    this.iptRef.current.focus();
  };
}
ReactDOM.render(<App></App>, document.getElementById('root'));
